import request from '@utils/request';
const version = InbizConfig.API_VERSION;

export function getModelData(params: { appId: string }): Promise<
  {
    Children: any[];
    IsMany: boolean;
    ModelKey: string;
    ModelName: string;
    ParentModelKey: string;
  }[]
> {
  return request(`/inbiz/api/services/modelengine/v${version}/model/manys/${params.appId}`);
}

export function getManyFields(params: { appId: string; modelKeys: string }): Promise<
  {
    Fields: { Name: string; Key: string }[];
  }[]
> {
  var modelKeysStr = params.modelKeys;
  var modelKeys = modelKeysStr.split('&modelKeys=');
  return request(`/inbiz/api/services/modelengine/v${version}/model/manyFields`, {
    method: 'post',
    data: {
      ...params,
      modelKeys,
      includeSystem: true,
    },
  });
}
